<style lang="less" scoped>
</style>
<template>
    <base-model
        @model-close="modelClose"
        @model-ok="modelOk"
        title="新建订单"
        :value="value"
        :loading="loading"
        @input="updateshow">
        <Form :model="form" :label-width="120" :ref="ref" :rules="rule">
            <FormItem label="订单编号：" prop="nub">
                <base-input v-model="form.nub" placeholder="请输入订单编号"></base-input>
            </FormItem>
            <FormItem label="客户订单编号：" prop="customernub">
                <base-input v-model="form.customernub" placeholder="请输入客户订单编号"></base-input>
            </FormItem>
            <FormItem label="数量：" prop="number">
                <base-input v-model="form.number" placeholder="请输入订单数量"></base-input>
            </FormItem>
            <FormItem label="客户：" prop="customermsg">
                <!--<base-input v-model="form.customermsg" placeholder="请选择客户"></base-input>-->
                <Select v-model="form.cid"  style="width:200px">
                    <Option v-for="item in customer" :value="item.id" :key="item.id">
                        <span>{{ item.name }}</span>
                        <span style="float:right;color:#ccc">{{ item.peoplename }}</span>
                    </Option>
                </Select>
            </FormItem>
            <FormItem label="产品：" prop="product">
                <Select v-model="form.pid"  style="width:200px">
                    <Option v-for="item in product" :value="item.id" :key="item.id">
                        <span>{{ item.name }}</span>
                        <span style="float:right;color:#ccc">{{ item.nub }}</span>
                    </Option>
                </Select>
            </FormItem>
            <FormItem label="总批次：" prop="allbatch">
                <base-input v-model="form.allbatch" placeholder="请输入总批次数"></base-input>
            </FormItem>
            <FormItem label="交期：" prop="delivery">
                <DatePicker :value="form.delivery" type="date" placeholder="Select date" style="width: 200px" @on-change="data => {form.delivery = new Date(data).getTime()}"></DatePicker>
            </FormItem>
            <FormItem label="预计出货时间：" prop="deliveryTime">
                <DatePicker :value="form.deliveryTime" type="date" placeholder="Select date" style="width: 200px"  @on-change="data => {form.deliveryTime = new Date(data).getTime()}"></DatePicker>
            </FormItem>
        </Form>
    </base-model>
</template>
<script>
    export default {
        name: 'adduser',
        props: {
            value: {
                type: Boolean,
                default: false
            },
            customer: {
                type: Array,
                default: () => {
                    return []
                }
            },
            product: {
                type: Array,
                default: () => {
                    return []
                }
            }
        },
        data () {
            return {
                ref: 'addorder',
                form: {
                    nub: '',
                    customernub: '',
                    customermsg: '',
                    number: '',
                    product: '',
                    allbatch: '',
                    delivery: '',
                    deliveryTime: ''
                },
                loading: true,
                rule: {
                    nub: this.rule.noNull('用户名不能为空')
                }
            }
        },
        computed: {
        },
        methods: {
            updateshow (show) {
                this.$emit('input', show)
            },
            addorderupdate (data) {
                this.$emit('addorderupdate', data)
            },
            reset () {
                this.$refs[this.ref].resetFields();
                /*this.addUserForm = {
                    name: '',
                    password: '',
                    passwordcheck: '',
                    power: []
                }*/
            },
            modelClose () {
                this.reset()
            },
            modelOk () {
                console.log(this.form)
                this.$refs[this.ref].validate((valid) => {
                    if (valid) {
                        this.http.addOrder(this, this.form)
                    } else {
                        this.loading = false
                        setTimeout(() => {
                            this.loading = true
                        }, 300)
                    }
                })

            }
        },
        components: {
        },
        mounted: function () {
        }
    };
</script>
